<template>
  <Model
    :title="row.edit ? '编辑' : '添加'"
    :width="800"
    :show="show"
    @confirm="confirm"
    @cancel="cancel"
  >
    <Form slot="form">
      <FormDoubleItem :labels="['名称', '编号']">
        <a-input
          slot="left"
          v-model="row.name"
          placeholder="请输入内容"
        ></a-input>
        <a-input
          slot="right"
          v-model="row.number"
          placeholder="请输入内容"
        ></a-input>
      </FormDoubleItem>
      <FormDoubleItem :labels="['导师工号', '成员']">
        <a-input
          slot="left"
          v-model="row.teacherId"
          placeholder="请输入内容"
        ></a-input>
        <a-input
          slot="right"
          v-model="row.member"
          placeholder="逗号隔开多个成员"
        ></a-input>
      </FormDoubleItem>
      <FormDoubleItem :labels="['级别', '状态']">
        <a-select
          slot="left"
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          :default-value="row.level"
          @change="(e) => changeValue(e, 'level')"
        >
          <a-select-option v-for="item in level" :key="item" :value="item">
            {{ item }}
          </a-select-option>
        </a-select>
        <a-select
          slot="right"
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          :default-value="row.status"
          @change="(e) => changeValue(e, 'status')"
        >
          <a-select-option
            v-for="item in teacherProjectStatus"
            :key="item"
            :value="item"
          >
            {{ item }}
          </a-select-option>
        </a-select>
      </FormDoubleItem>
      <FormDoubleItem :labels="['类型', '审核']">
        <a-select
          slot="left"
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 200px"
          :default-value="row.type"
          @change="(e) => changeValue(e, 'type')"
        >
          <a-select-option
            v-for="item in teacherProjectType"
            :key="item.id"
            :value="item.id"
          >
            {{ item.name }}
          </a-select-option>
        </a-select>
        <a-select
          slot="right"
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          :disabled="row.edit"
          :default-value="row.check"
          @change="(e) => changeValue(e, 'check')"
        >
          <a-select-option v-for="item in check" :key="item" :value="item">
            {{ item }}
          </a-select-option>
        </a-select>
      </FormDoubleItem>
      <FormDoubleItem :labels="['年份', '申报书']">
        <a-input
          slot="left"
          v-model="row.year"
          placeholder="请输入内容"
        ></a-input>
        <a-upload
          slot="right"
          :file-list="fileList"
          :multiple="false"
          :remove="handleRemove"
          :before-upload="beforeUpload"
        >
          <a-button> <a-icon type="upload" /> 选择文件 </a-button>
        </a-upload>
      </FormDoubleItem>
      <!-- <FormAlignItem label="申报书">
        <a-upload
          :file-list="fileList"
          :multiple="false"
          :remove="handleRemove"
          :before-upload="beforeUpload"
        >
          <a-button> <a-icon type="upload" /> 选择文件 </a-button>
        </a-upload>
      </FormAlignItem> -->
    </Form>
  </Model>
</template>

<script>
import Model from "components/common/model/Model";
import Form from "components/common/form/Form";
import FormItem from "components/common/form/formItem/FormItem";
import FormLenItem from "components/common/form/formItem/FormLenItem";
import FormDoubleItem from "components/common/form/formDoubleItem/FormDoubleItem";
import FormAlignItem from "components/common/form/formAlignItem/FormAlignItem";
import {
  teacherProjectType,
  check,
  teacherProjectStatus,
  level,
} from "assets/data/other";
import { hasPropertyEmpty } from "common/index";

export default {
  components: {
    Model,
    Form,
    FormDoubleItem,
    // FormAlignItem,
    // FormLenItem,
  },
  props: {
    row: {
      type: Object,
      default() {
        return {};
      },
    },
    show: {
      type: Boolean,
      defalut: false,
    },
  },
  data() {
    return {
      check,
      teacherProjectStatus,
      level,
      fileList: [],
      teacherProjectType,
    };
  },
  methods: {
    beforeUpload(file) {
      this.fileList = [file];
      this.row.file = file;
      return false;
    },
    handleRemove(file) {
      const index = this.fileList.indexOf(file);
      const newFileList = this.fileList.slice();
      newFileList.splice(index, 1);
      this.fileList = newFileList;
      this.row.file = "";
    },

    changeValue(value, key) {
      this.row[key] = value;
    },

    confirm() {
      const row = this.row;
      // if (!row.edit && hasPropertyEmpty(row)) return;

      row.level = level.indexOf(row.level);
      row.status = teacherProjectStatus.indexOf(row.status);
      row.check = check.indexOf(row.check);
      row.year = row.year ? +row.year : new Date().getFullYear();

      this.$emit("confirm", {
        ...row,
      });
    },
    cancel() {
      this.$emit("cancel");
    },
  },
};
</script>

<style lang="less" scoped>
.t-form {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-items: center;
  padding-right: 30px;
  .ant-btn {
    width: 200px !important;
  }
}
</style>